package com.tang.service;

import com.tang.event.EventManager;
import com.tang.event.listener.impl.MQEventListener;
import com.tang.event.listener.impl.MessageEventListener;
import com.tang.vo.LotteryResult;

public abstract class ALotteryService {

    private final EventManager eventManager;

    public ALotteryService() {
        this.eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.MSG);
        this.eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
        this.eventManager.subscribe(EventManager.EventType.MSG, new MessageEventListener());
    }

    LotteryResult draw(String uId) {
        LotteryResult lotteryResult = doDraw(uId);
        // 需要什么通知就调用什么方法
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        eventManager.notify(EventManager.EventType.MSG, lotteryResult);
        return lotteryResult;
    }

    protected abstract LotteryResult doDraw(String uId);

}
